<template>
  <div class="app-container">
    <div class="content-box">
      <el-form
        v-show="showSearch"
        ref="queryForm"
        :model="queryParams"
        :inline="true"
        label-width="68px"
      >
        <el-form-item label="商品名称" prop="channel_id">
          <el-input
            v-model="shop_name"
            placeholder="请输入商品名称"
            clearable
          />
        </el-form-item>
        <el-form-item
          label="商品sku编码"
          prop="junction_time"
          label-width="100px"
        >
          <el-input
            v-model="shop_sku"
            placeholder="请输入商品sku编码"
            clearable
          />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
      <el-row :gutter="10" class="mb8">
        <right-toolbar :show-search.sync="showSearch" @queryTable="getList" />
      </el-row>

      <el-row :gutter="10" class="mb8">
        <div class="moban_box">
          下载调价模板：<a :href="downloadUrl" style="color: #0766fe"
            >导入模板</a
          >
        </div>
      </el-row>
      <el-row :gutter="10" class="mb8">
        <el-upload
          class="upload-demo"
          :action="upload.url"
          :on-success="goodsImports"
          :show-file-list="false"
          multiple
        >
          <el-button plain type="warning" icon="el-icon-bottom" size="mini"
            >导入调价</el-button
          >
        </el-upload>
      </el-row>

      <el-table
        v-loading="loading"
        :data="list"
        row-key="id"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="50" align="center" />
        <el-table-column prop="id" label="商品名称" width="80" />
        <el-table-column
          prop="supply_price_ratio"
          label="商品sku编码"
          width="100"
        />
        <el-table-column prop="junction_time" label="调价时间" align="center" />
        <el-table-column prop="starttime" label="原供货价" align="center" />
        <el-table-column prop="endtime" label="调整后货价" align="center" />
        <el-table-column
          prop="order_sum"
          label="差异（+10，-22）"
          align="center"
        />
        <!-- <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              v-hasPermi="['finance:bill']"
              size="mini"
              type="text"
              icon="el-icon-text"
              @click="handleInfo(scope.row)"
              >详情</el-button
            >
            <el-button
              v-hasPermi="['finance:settlement']"
              size="mini"
              type="text"
              icon="el-icon-text"
              v-if="scope.row.order_status === 2"
              @click="handleSettlement(scope.row)"
              >结存</el-button
            >
          </template>
        </el-table-column> -->
      </el-table>
      <pagination
        v-show="totalSize > 0"
        :total="totalSize"
        :page.sync="queryParams.page"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
// import { listFinance, getChannel,settlementFinance } from '@/api/finance/index'

export default {
  name: "FinanceIndex",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 选中数组
      ids: [],
      // 数据
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 显示状态数据字典
      visibleOptions: [],
      // 菜单状态数据字典
      statusOptions: [],
      // 查询参数
      queryParams: {
        page: 1,
        pageSize: 10,
        junction_time: "",
        channel_id: "",
      },
      totalSize: 1,
      // 非多个禁用
      multiple: true,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        name: [
          { required: true, message: "物流名称不能为空", trigger: "blur" },
        ],
      },
      // 用户导入参数
      upload: {
        // 是否禁用上传
        isUploading: false,
        // 设置上传的请求头部
        headers: {},
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "common/upload",
      },
      channelList: [],
    };
  },
  created() {
    this.getList();
    this.getChannel();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = false;
      listFinance(this.queryParams).then((response) => {
        this.list = response.data.list;
        this.totalPage = response.data.totalPage;
        this.totalSize = response.data.total;
        this.loading = false;
      });
    },
    getChannel() {
      getChannel().then((response) => {
        this.channelList = response.data;
        if (this.channelList.length > 0) {
          this.queryParams.channel_id = this.channelList[0].id;
        }
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
      };
      this.resetForm("form");
      this.fileList = [];
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },

    handleInfo(row) {
      this.$router.push({
        path: "/finance/bill",
        query: {
          id: row.id,
        },
      });
    },
    handleSettlement(row) {
      settlementFinance({ id: row.id }).then((res) => {
        this.msgSuccess("操作成功");
        this.getList();
      });
    },
  },
};
</script>
<style lang="scss" scoped>
img {
  width: 100%;
}
</style>
